864A - Fair Game - CodeForces Solution


implementation sortings *1000

Please click on ads to support us..

Python Code:

from collections import Counter  
n = int(input()) 
a = []
for _ in range(n) : a.append(int(input())) 
s = set(a) 
if len(s) != 2 : print("NO") 
else : 
    cnt = Counter(a) 
    l = []
    for i in s : l.append(cnt[i])
    if l[0] == l[1] : 
        print("YES")
        for i in s : print(i, end = ' ') 
    else : print("NO")

C++ Code:

#include<bits/stdc++.h>
using namespace std;

main()
{
    int n;
    cin>>n;
    int V[101]={0};
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        V[x]++;
    }
    bool flag=0;
    for(int i=1;i<=100;i++)
    {
        for(int j=i+1;j<=100;j++)
        {
            if(V[i]==V[j] && V[i]>0 && V[j]>0 && (V[i]+V[j]==n))
               {
                   flag=1;
                   cout<<"YES\n"<<i<<" "<<j<<"\n";
                    break;
               }
        }
    }
    if(flag==0)
    {
        cout<<"NO\n";
    }

}

 				 			 		     	 					    			


Comments

Submit
0 Comments
More Questions

3B - Lorry
1392A - Omkar and Password
489A - SwapSort
932A - Palindromic Supersequence
433A - Kitahara Haruki's Gift
672A - Summer Camp
1277A - Happy Birthday Polycarp
577A - Multiplication Table
817C - Really Big Numbers
1355A - Sequence with Digits
977B - Two-gram
993A - Two Squares
1659D - Reverse Sort Sum
1659A - Red Versus Blue
1659B - Bit Flipping
1480B - The Great Hero
1519B - The Cake Is a Lie
1659C - Line Empire
515A - Drazil and Date
1084B - Kvass and the Fair Nut
1101A - Minimum Integer
985D - Sand Fortress
1279A - New Year Garland
1279B - Verse For Santa
202A - LLPS
978A - Remove Duplicates
1304A - Two Rabbits
225A - Dice Tower
1660D - Maximum Product Strikes Back
1513A - Array and Peaks